home *** CD-ROM | disk | FTP | other *** search
/ Plug-In Power Pack for Netscape Communicator / Plug-In Power Pack for Netscape Communicator.iso / plugins / dataviews / dvtools / examples / windows / dv_win / dv_win.c next >
Encoding:
C/C++ Source or Header  |  1997-05-08  |  9.3 KB  |  318 lines

  1. #include <windows.h>
  2.  
  3. #include "std.h"
  4. #include "dvtools.h"
  5. #include "dvstd.h"
  6. #include "Tfundecl.h"
  7. #include "dvGR.h"
  8.  
  9. #include "dv_win.h"
  10.  
  11. long CALLBACK MyWinProc( HWND, UINT, WPARAM, LPARAM );
  12.  
  13. LOCAL void UpdateDVwindow();
  14. LOCAL void init_window( char *, HANDLE, int ), init_dv(), term_dv();
  15.  
  16. LOCAL VIEW MyView[3], ActiveView;
  17. LOCAL DRAWPORT Dp[3], ActiveDrawport;
  18. LOCAL OBJECT screen;
  19.  
  20. LOCAL HWND dv_window;
  21.  
  22. LRESULT  (CALLBACK * dv_winproc)() = NULL ;
  23.  
  24. int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  25.                       LPSTR lpCmdLine, int nCmdShow )
  26. {
  27.  
  28.     MSG msg;
  29.  
  30.  
  31.     /* Register, Create and Draw a window */
  32.    init_window( "DV_WIN", hInstance, nCmdShow );
  33.  
  34.    /* Initialize the DataViews Stuff */
  35.    init_dv();
  36.  
  37.    /* Go into the Message Loop */
  38.    while( GetMessage(&msg, NULL, 0,0) )
  39.    {
  40.       TranslateMessage( &msg );
  41.       DispatchMessage( &msg );
  42.    }
  43.  
  44.     return msg.wParam;
  45. }
  46.  
  47. LOCAL void init_window( char *class_name, HANDLE hInstance, int nCmdShow )
  48. {
  49.     WNDCLASS wndclass;
  50.  
  51.     /* Register the Class */
  52.     wndclass.style = CS_OWNDC;            /* default style */
  53.     wndclass.hInstance = hInstance;
  54.     wndclass.lpszClassName = class_name;
  55.     wndclass.lpszMenuName = "dvMenu";
  56.     wndclass.hIcon = LoadIcon( NULL, IDI_APPLICATION );
  57.     wndclass.hCursor = LoadCursor( NULL, IDC_ARROW );
  58.     wndclass.hbrBackground = GetStockObject( GRAY_BRUSH );
  59.     wndclass.lpfnWndProc = MyWinProc;
  60.     wndclass.cbClsExtra = 0;
  61.     wndclass.cbWndExtra = 0;
  62.  
  63.     RegisterClass( &wndclass );
  64.  
  65.     /* Create an Instance of the Class */
  66.     dv_window = CreateWindow( class_name, class_name,
  67.                               WS_OVERLAPPEDWINDOW,
  68.                               CW_USEDEFAULT,
  69.                               CW_USEDEFAULT,
  70.                               500, 400,
  71.                               NULL,
  72.                               NULL,
  73.                               hInstance,
  74.                               NULL );
  75.  
  76.     /* Display the Window */ 
  77.     ShowWindow( dv_window, nCmdShow );
  78.     UpdateWindow( dv_window );
  79.  
  80.     /* Create a Timer */
  81.     SetTimer( dv_window, 1, 100, NULL );
  82. }
  83.  
  84. LOCAL void init_dv()
  85. {
  86.     /* Initialize DataViews */
  87.     TInit( NULL, NULL );
  88.  
  89.     /* Pass the window onto DataViews */
  90.     screen = TscOpenSet( "W", NULL,
  91.                          V_WIN32_WINDOW_HANDLE, dv_window,
  92.                          V_ACTIVE_CURSOR,
  93.                          V_END_OF_LIST );
  94.  
  95.     /* get a pointer to the function that would */
  96.     /* be the window proc for a window created  */
  97.     /* with TscOpenSet                          */
  98.     GRget(V_WIN32_WINDOWPROC,&dv_winproc,V_END_OF_LIST);
  99.     GRset(V_WIN32_DOUBLE_BUFFER,TRUE,V_END_OF_LIST);
  100.  
  101.     /* Load the two Views, Create Drawports and Draw */
  102.     MyView[1] = TviLoad( "view1.v" );
  103.     TviOpenData( MyView[1] );
  104.     MyView[2] = TviLoad( "view2.v" );
  105.     TviOpenData( MyView[2] );
  106.     MyView[0] = TviLoad( "view3.v" );
  107.     TviOpenData( MyView[0] );
  108.     ActiveView = MyView[0];
  109.  
  110.     Dp[0] = TdpCreate( screen, MyView[0], (RECTANGLE*)NULL, (RECTANGLE*)NULL );
  111.     Dp[1] = TdpCreate( screen, MyView[1], (RECTANGLE*)NULL, (RECTANGLE*)NULL );
  112.     Dp[2] = TdpCreate( screen, MyView[2], (RECTANGLE*)NULL, (RECTANGLE*)NULL );
  113.     ActiveDrawport = Dp[0];
  114.  
  115.     TviReadData( ActiveView );
  116.     TdpDraw( ActiveDrawport );
  117. }
  118.  
  119. LOCAL void term_dv()
  120. {
  121.     return;
  122.  
  123.     TdpDestroy( Dp[0] );
  124.     TdpDestroy( Dp[1] );
  125.     TdpDestroy( Dp[2] );
  126.  
  127.     TviDestroy( MyView[0] );
  128.     TviDestroy( MyView[1] );
  129.     TviDestroy( MyView[2] );
  130.  
  131.     TscCloseCurrentScreen();
  132.  
  133.     TTerminate();
  134. }
  135.  
  136. /* this window proc calls the dataviews window proc to   */
  137. /* handle any messages that need not be handled directly */
  138. /* by this app. some of the things this proc lets the    */
  139. /* dataviews window proc handle are:                     */
  140. /*   mapping of windows messages to expose events        */
  141. /*   mapping of windows messages to resize events        */
  142. /*   color table handling                                */
  143. /* Handle any messages you wish. If you handle the       */
  144. /* message there is no need to call the dataviews window */
  145. /* proc and you should not do so.                        */
  146. long CALLBACK MyWinProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam  )
  147. {
  148.            PAINTSTRUCT ps;
  149.            int         id;
  150.            MSG         a_msg;          /* used to call GRwe_convert() */
  151.            WINEVENT    win_event;      /* used to call GRwe_convert() */
  152.     static int         times  = 0;     /* used as a counter to toggle */
  153.                                        /* double buffering on and off */
  154.     static int         a_bool = TRUE;  /* true for turning on double */
  155.                                        /* buffering */
  156.     static int         ok_to_draw=TRUE;
  157.  
  158.     switch( msg )
  159.     {
  160.       case WM_CANCELMODE:
  161.         /* this message will be sent when the graph view is */
  162.         /* is sized too small and a message box displays    */
  163.         /* the viewport too small message. redrawing the    */
  164.         /* view while the message box is up will result in  */
  165.         /* an endless stream of errors.                     */
  166.         ok_to_draw = FALSE;
  167.         return(0);
  168.         break;
  169.       case WM_ACTIVATE:
  170.         /* this message is sent when the message box is     */
  171.         /* dismissed                                        */
  172.         if (  ( LOWORD(wParam) == WA_ACTIVE ) ||
  173.               ( LOWORD(wParam) == WA_CLICKACTIVE ) )
  174.         ok_to_draw = TRUE;
  175.         return(0);
  176.         break;
  177.       case WM_DESTROY:
  178.         term_dv();
  179.         PostQuitMessage( 0 );
  180.         return( 0 );
  181.         break;
  182.  
  183.       case WM_TIMER:
  184.         if ( ok_to_draw == TRUE )
  185.           UpdateDVwindow();       
  186.         times++;
  187.         if ( times % 30 == 0  )
  188.         {
  189.           /* every 30 times the timer sends a message */
  190.           /* toggle the state of double buffering     */
  191.           a_bool = ( a_bool == TRUE ) ? FALSE : TRUE;
  192.           GRset(V_WIN32_DOUBLE_BUFFER,a_bool,0);
  193.         }
  194.         break;
  195.  
  196.       case WM_SYSCOMMAND:
  197.         switch (LOWORD (wParam))
  198.         {
  199.           case SC_CLOSE:
  200.             PostQuitMessage( 0 );
  201.             return( 0 );
  202.             break;
  203.                
  204.             default:
  205.               return DefWindowProc( hwnd, msg, wParam, lParam );
  206.         }
  207.         break;
  208.          
  209.       case WM_COMMAND:
  210.         switch( LOWORD( wParam) )
  211.         {
  212.           case IDM_QUIT:
  213.             term_dv();
  214.             PostQuitMessage( 0 );
  215.             return( 0 );
  216.             break;
  217.           case IDM_GRAPH:
  218.             ActiveView = MyView[0];
  219.             ActiveDrawport = Dp[0];
  220.             TdpDraw( ActiveDrawport );
  221.             break;
  222.           case IDM_ANIM:
  223.             ActiveView = MyView[1];
  224.             ActiveDrawport = Dp[1];
  225.             TdpDraw( ActiveDrawport );
  226.             break;
  227.           case IDM_LOGO:
  228.             ActiveView = MyView[2];
  229.             ActiveDrawport = Dp[2];
  230.             TdpDraw( ActiveDrawport );
  231.             break;
  232.         }
  233.         break;
  234.       case WM_LBUTTONDOWN:
  235.         if( ActiveDrawport == Dp[0] )
  236.           id = 1;
  237.         else
  238.           if ( ActiveDrawport == Dp[1] )
  239.             id = 2;
  240.           else
  241.             id = 0;
  242.         ActiveView = MyView[id];
  243.         ActiveDrawport = Dp[id];
  244.         TdpDraw( ActiveDrawport );
  245.         break;
  246.  
  247.       case WM_CHAR:
  248.         if ( (wParam == 'c') || ( wParam == 'C' ) )
  249.           GRerase();
  250.         break;
  251.  
  252.       /*  VI_RESIZE and VI_EXPOSE are defined in dvGR.h */
  253.  
  254.       case VI_EXPOSE: 
  255.         a_msg.hwnd = hwnd;
  256.         a_msg.message = msg;
  257.         a_msg.wParam = wParam;
  258.         a_msg.lParam = lParam;
  259.         /* here, GRwe_convert() will fill in the region that  */
  260.         /* should be sent with TscRedraw                      */
  261.         GRwe_convert(&a_msg,&win_event);
  262.         if ( ok_to_draw == TRUE )
  263.           TscRedraw(screen,&(win_event.region)); 
  264.         break;    
  265.  
  266.       case VI_RESIZE:
  267.         TscReset(screen);
  268.         break;
  269.  
  270.       case WM_PAINT:
  271.         if ( dv_winproc == NULL )
  272.         {    
  273.           BeginPaint(hwnd, &ps);
  274.           EndPaint(hwnd,&ps);
  275.         }
  276.         else
  277.         {
  278.           /* this is how you should handle a WM_PAINT message for */
  279.           /* a DVtools window */
  280.           a_msg.hwnd = hwnd;
  281.           a_msg.message = msg;
  282.           a_msg.wParam = wParam;
  283.           a_msg.lParam = lParam;
  284.           /* GRwe_convert will call BeginPaint() and EndPaint()     */
  285.           /* and fill in the win_event structure with the rectangle */
  286.           /* that needs to be redrawn                               */
  287.           GRwe_convert(&a_msg,&win_event);
  288.           if ( win_event.type == V_EXPOSE )
  289.             TscRedraw(screen,&(win_event.region));
  290.         }
  291.         return(0);
  292.         break;
  293.      
  294.       default:
  295.         /* using this method will also take care of */
  296.         /* handling the color table.                */
  297.         if ( dv_winproc != NULL )
  298.         {
  299.            return( CallWindowProc(dv_winproc,hwnd, msg, wParam, lParam ));
  300.         }
  301.         return DefWindowProc( hwnd, msg, wParam, lParam );
  302.         break;
  303.     }
  304.   return(0);
  305. }
  306.  
  307. LOCAL void UpdateDVwindow()
  308. {
  309.  
  310.     TviReadData( ActiveView );
  311.     TdpDrawNext( ActiveDrawport );
  312. }
  313.  
  314. LOCAL void HandleDVwindowEvents()
  315. {
  316.  
  317. }
  318.